$(function(){
	$('#setButton').click(function(){
		//输入检查，MD5加密
		var input_pwd = document.getElementById('input_pwd');
	    var opwd = document.getElementById('opwd');
	    var npwd = document.getElementById('npwd');
	    var cpwd = document.getElementById('cpwd');
	    if(input_pwd.value==""||input_pwd.value===null||input_pwd.value===undefined){
	    	event.preventDefault();
	    	alert("请输入原密码！");
	    	return;
	    }else if(npwd.value==""||npwd.value===null||npwd.value===undefined){
	    	event.preventDefault();
	    	alert("请输入新密码!");
	    	return;
	    }else if(cpwd.value==""||cpwd.value===null||cpwd.value===undefined){
	    	event.preventDefault();
	    	alert("请再次输入新密码!");
	    	return;
	    }else{
	    	opwd.value =  hex_md5(input_pwd.value); 
	    }
	    //提交密码
        var formdata=new FormData();
        formdata.append('opwd', opwd.value);
        formdata.append('npwd', npwd.value);
        formdata.append('cpwd', cpwd.value);
        $.ajax({
            url:'changepwd',
            type:'post',
            dataType: 'json',
            data:formdata,
            processData:false,
            contentType:false,
            success:function(info){    
                if(info.code==0&&info.data==1) {
                	alert("修改成功，请点击确定重新登陆！");
                	window.location.href = "login";
                }else if(info.code==500200){
                	alert("原密码错误！");
                }else if(info.code==500201) {
                	alert("两次密码不一致！");
                }else {
                	alert("修改失败！");
                }
            },
            error:function(err){
            	alert("连接失败！");
            }
        });
	})
})